package com.cssw.fyzb.core.dao.pay;

import com.cssw.fyzb.core.model.dodb.QuickSignOrder;
import com.cssw.fyzb.core.model.dodb.UserQuickSign;
import org.springframework.stereotype.Repository;

import java.util.Date;

/**
 * @Author: yangyiqun
 * @Date: 2021/2/17 14:20
 */
@Repository
public class QuickSignOrderDaoImpl implements QuickSignOrderDao {

    @Override
    public Long save(Long userId, String cardNo, String realName, String bankName, String bankCode, String certCode, String mobile, String orderNo, String idCard, String busiNo) {
        QuickSignOrder order = new QuickSignOrder();
        order.setUserId(userId);
        order.setCardNo(cardNo);
        order.setRealName(realName);
        order.setBankName(bankName);
        order.setBankCode(bankCode);
        order.setCertCode(certCode);
        order.setMobile(mobile);
        order.setOrderNo(orderNo);
        order.setIdCard(idCard);
        order.setBusiNo(busiNo);
        order.setStatus(QuickSignOrder.STATUS_INIT);
        order.setCreateTime(new Date());
        order.save();
        return order.getSignId();
    }

    @Override
    public void updateSuccess(Long signId) {
        QuickSignOrder order = new QuickSignOrder();
        order.setSignId(signId);
        order.setStatus(QuickSignOrder.STATUS_SUCC);
        order.setUpdateTime(new Date());
        order.update();
    }

    @Override
    public void updateFail(Long signId, String errorCode, String errorMsg) {
        QuickSignOrder order = new QuickSignOrder();
        order.setSignId(signId);
        order.setStatus(QuickSignOrder.STATUS_FAIL);
        order.setUpdateTime(new Date());
        order.setErrorCode(errorCode);
        order.setErrorMsg(errorMsg);
        order.update();
    }

    @Override
    public QuickSignOrder getByOrderNo(String orderNo) {
        String sql = "select * from t_quick_sign_order where order_no = ?";
        return QuickSignOrder.dao.findFirst(sql, orderNo);
    }
}
